/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 * @flow
 */

// module
import Taro, { Component } from '@tarojs/taro';
import {Input} from '@tarojs/components';
import { AtInput } from 'taro-ui';

// project
import { CPage, CContent, CHeader, CFooter, CFloat, CAround, CBetween, CCenter, CRow, CWrap, CLine, CHand, CItemX, CItemY, CText, CLabel, CSvg, CImage, CButton, CColumn } from '../../library/comp';
import { Base64, Gen, Time, Zip, Session, Storage, Toast} from '../../library/func';
import Icon from '../../project/style/icon';
import Http from '../../project/func/http/http';
import '../../library/style/patch.css';

// 引用组件
// import { Addcbtn, Editcunit } from '../../project/comp';

/******************************************************************************************
 * Export Class
 ******************************************************************************************/


export default class EditIndex extends Component {
	constructor(props) {
		super(props);

		/**
		 * state
		 */
		this.state = {
			// 获取屏幕高度
            scrollHeight: wx.getSystemInfoSync().windowHeight,
			value:'服装',
			// 从详情页面传过来的相册或者分类的id
			id: 0,
			// 从详情页面传过来的相册或者分类的名字
			name: '',
		}
	}
	
	/*------------------------------------------------------------------------------------
	* 声明周期
	*-----------------------------------------------------------------------------------*/
	// didMount
	componentDidMount(){
		console.log('454646===============',this.$router.params)
		this.setState({
			id: this.$router.params.id,
			name: this.$router.params.name
		})
	}
	// didshow
	componentDidShow(){

	}

    /*------------------------------------------------------------------------------------
	 * 自定义方法
	 *-----------------------------------------------------------------------------------*/
	// 更改input的value
     changeValue = value =>{
         this.setState({
             name:value.detail.value
         })
	 }
	
	// 清除input的value
	onClear = ()=> {
		this.setState({
			name: ' '
		})
	}

	// onRedirect
	onRedirect(url){
		wx.redirectTo({
			url: url
		})
	}
	    
	// onNavigate
	onNavigate(url){
	    wx.navigateTo({
	        url: url
	    })
	}
	    
	//onNavigateBack
	onNavigateBack(num){
	     wx.navigateBack({
	        delta: num
	     })                    
	}

	// 编辑相册名称
	update = ()=> {
		Http.post({
			url: 'materialCate/logic/update.php',
			data:{
				id: this.state.id,
				set_name: this.state.name
			},
			success: (data)=> {
				Toast.success('修改成功')
				setTimeout(()=>{
					wx.navigateBack({
				        delta: 2
				     }) 
				},1500)
			}
		})
	}  
	
	/**
	 * 渲染
	 */
	render() {
		return (
			<CPage>
				<CContent h={this.state.scrollHeight + 'px'}>
                    <CBetween bg='#fff' pa='10'>
                        <CHand color='#cbb383' size='16' onClick={this.onNavigateBack.bind(this, 2)}>取消</CHand>
                        <CHand color='#cbb383' size='16' onClick={this.update}>完成</CHand>
                    </CBetween>
                    <CLine mt='15' ml='10' mb='4' size='15' color='#868686'>相册标题</CLine>
					<CBetween bg='#fff' h='50' px='10'>
						<Input
							name='value'
							type='text'
							placeholder='请输入标题'
							value={this.state.name}
							onInput={this.changeValue.bind(this)}
							style='font-size:26rpx; width:100%; height:40px;'
							focus
							// class='atinputP15'
							// clear
						/>
						<CHand w='20' h='20' ra='50' bg='#c5c5c5'  x='center' y='top' pt='-8' onClick={this.onClear}>
							<CText color='#fff' mt='-1' size='14'>x</CText>
						</CHand>
					</CBetween>
                    
				</CContent>
			</CPage>
		);
	}
}

